﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutoTestEntry.SpecificUtility;

namespace AutoTestEntry.UI
{
    public partial class EnvSettingsForm : Form
    {
		private EnvDepoly envDeploy;
        public EnvSettingsForm(String[] envs)
        {
            InitializeComponent();
            Init();

            txtNetPath.Text = envs[0];
            txtSVNPath.Text = envs[1];
            txtNUnitPath.Text = envs[2];
            txtDestPath.Text = envs[3];
        }

        private void Init()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;

            txtNetPath.MouseDoubleClick += txtNetPath_MouseDoubleClick;
            txtSVNPath.MouseDoubleClick += txtSVNPath_MouseDoubleClick;
            txtNUnitPath.MouseDoubleClick += txtNUnitPath_MouseDoubleClick;
            txtDestPath.MouseDoubleClick += txtDestPath_MouseDoubleClick;

            btnSave.Click += btnSave_Click;
            btnCancel.Click += btnCancel_Click;

			envDeploy = new EnvDepoly();
        }

        private void txtNetPath_MouseDoubleClick(Object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = ".Net 3.5| *.exe";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtNetPath.Text = dialog.FileName;
            }
        }

        private void txtSVNPath_MouseDoubleClick(Object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "SVN| *.exe";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtSVNPath.Text = dialog.FileName;
            }
        }

        private void txtNUnitPath_MouseDoubleClick(Object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "NUnit| *.exe";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtNUnitPath.Text = dialog.FileName;
            }
        }

        private void txtDestPath_MouseDoubleClick(Object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtDestPath.Text = dialog.SelectedPath;
            }
        }

        private void btnSave_Click(Object sender, EventArgs e)
        {
            if (txtNetPath.Text.Length == 0 || 
                txtSVNPath.Text.Length == 0 ||
                txtNUnitPath.Text.Length == 0 ||
                txtDestPath.Text.Length == 0)
            {
                MessageBox.Show("请设置完整", "设置不完全");
                return;
            }

			envDeploy.SetEnvironment(txtNetPath.Text, txtSVNPath.Text, txtNUnitPath.Text, txtDestPath.Text);
            this.Dispose();
        }

        private void btnCancel_Click(Object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
